<?php


namespace app\index\controller;

use app\index\model\File as FileModel;
use app\index\model\Notice as NoticeModel;
use app\index\model\Result as ResultModel;
use think\Db;
use think\Request;

class Result extends Base
{
    //成绩列表
    public function  resultList()
    {
        $this -> view -> assign('title', '成绩列表');
        $this -> view -> assign('keywords', '软件工程专业教学管理系统');
        $this -> view -> assign('desc', '软件工程专业教学管理系统');
        $this -> view -> count = ResultModel::count();
        $resultList = ResultModel::paginate(5);

        $this -> view -> assign('resultList', $resultList);

        //渲染成绩列表模板
        return $this -> view -> fetch('result_list');
    }

    //添加操作的界面
    public function  resultAdd()
    {
        $this->view->assign('title','添加管理员');
        $this->view->assign('keywords','软件工程专业教学管理系统');
        $this->view->assign('desc','软件工程专业教学管理系统');
        return $this->view->fetch('result_add');
    }

    //添加操作
    public function addResult(Request $request)
    {
        //从提交表单中获取数据
        $data = $request -> param();

        //向表中新增记录
        $result = ResultModel::create($data);

        //设置返回数据
        $status = 0;
        $message = '添加失败,请检查';

        //检测更新结果,将结果返回给result_add模板中的ajax提交回调处理
        if (true == $result) {
            $status = 1;
            $message = '恭喜, 添加成功~~';
        }
        return ['status'=>$status, 'message'=>$message];
    }

    //渲染编辑成绩界面
    public function resultEdit(Request $request)
    {
        $result_id = $request -> param('id');
        $result = ResultModel::get($result_id);
        $this->view->assign('title','编辑通知');
        $this->view->assign('keywords','软件工程专业教学管理系统');
        $this->view->assign('desc','软件工程专业教学管理系统');
        $this->view->assign('result_info',$result->getData());
        return $this->view->fetch('result_edit');
    }

    //更新数据操作
    public function editResult(Request $request)
    {
        $data = $request -> param();

        //设置更新条件
        $condition = ['id'=>$data['id']];

        //更新当前记录
        $result = ResultModel::update($data,$condition);

        //设置返回数据
        $status = 0;
        $message = '更新失败,请检查';

        //检测更新结果,将结果返回给notice_edit模板中的ajax提交回调处理
        if (true == $result) {
            $status = 1;
            $message = '恭喜, 更新成功~~';
        }
        return ['status'=>$status, 'message'=>$message];
    }

}